找传奇、传世资源到传世资源站!

PWM输出(实验)

8.5玩家评分(1人评分)
下载后可评
介绍 评论 失效链接反馈

在PA6持续输出pwm,占空比为50%from clipboard GPIO_InitTypeDef GPIO_InitStructure;
TIM_TimeBaseInitTypeDef  TIM_TimeBaseStructure;
TIM_OCInitTypeDef  TIM_OCInitStructure;

RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM3,ENABLE);  //TIM3ʱÖÓʹÄÜ    
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOA, ENABLE); //ʹÄÜPORTAʱÖÓ

GPIO_PinAFConfig(GPIOA,GPIO_PinSource6,GPIO_AF_TIM3); //GPIOA6¸´ÓÃΪ¶¨Ê±Æ÷3
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_6 |GPIO_Pin_7;           //GPIOFA
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;        //¸´Óù¦ÄÜ
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz; //ËÙ¶È100MHz
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;      //ÍÆÍ츴ÓÃÊä³ö
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;        //ÉÏÀ­
GPIO_Init(GPIOA,&GPIO_InitStructure);              //³õʼ»¯PA6
  
TIM_TimeBaseStructure.TIM_Prescaler=psc;  //¶¨Ê±Æ÷·ÖƵ
TIM_TimeBaseStructure.TIM_CounterMode=TIM_CounterMode_Up; //ÏòÉϼÆÊýģʽ
TIM_TimeBaseStructure.TIM_Period=arr;   //×Ô¶¯ÖØ×°ÔØÖµ
TIM_TimeBaseStructure.TIM_ClockDivision=TIM_CKD_DIV1; 

TIM_TimeBaseInit(TIM3,&TIM_TimeBaseStructure);//³õʼ»¯¶¨Ê±Æ÷3

//³õʼ»¯TIM14 Channel1 PWMģʽ  
TIM_OCInitStructure.TIM_OCMode = TIM_OCMode_PWM1; //Ñ¡Ôñ¶¨Ê±Æ÷ģʽ:TIMÂö³å¿í¶Èµ÷ÖÆģʽ2
  TIM_OCInitStructure.TIM_OutputState = TIM_OutputState_Enable; //±È½ÏÊä³öʹÄÜ
TIM_OCInitStructure.TIM_OCPolarity = TIM_OCPolarity_Low; //Êä³ö¼«ÐÔ:TIMÊä³ö±È½Ï¼«ÐÔµÍ
TIM_OC1Init(TIM3, &TIM_OCInitStructure);  //¸ù¾ÝTÖ¸¶¨µÄ²ÎÊý³õʼ»¯ÍâÉèTIM1 4OC1

TIM_OC1PreloadConfig(TIM3, TIM_OCPreload_Enable);  //ʹÄÜTIM3ÔÚCCR1ÉϵÄԤװÔؼĴæÆ÷
 
  TIM_ARRPreloadConfig(TIM3,ENABLE);//ARPEʹÄÜ 

TIM_Cmd(TIM3, ENABLE);  //ʹÄÜTIM3

评论

发表评论必须先登陆, 您可以 登陆 或者 注册新账号 !


在线咨询: 问题反馈
客服QQ:174666394

有问题请留言,看到后及时答复